//
//  BCTabBarVC.m
//  BaoYouYou
//
//  Created by caobo56 on 2016/12/4.
//  Copyright © 2016年 caobo56. All rights reserved.
//

#import "BCTabBarVC.h"
#import "JDDGuidanceView.h"

#import "Live-Header.h"
#import "UIImage+Color.h"

@interface BCTabBarVC ()

@end

@implementation BCTabBarVC{
    JDDGuidanceView * guidView;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.backgroundImage = [[UIImage alloc] init];
    self.tabBar.shadowImage = [[UIImage alloc] init];
    [self setSelectedIndex:0];
    [self addGuidanceView];

    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self configureControllers];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)configureControllers {
    [[UITabBar appearance] setBackgroundColor:DEFAULTREDCOLOR];
    
    NSArray *selectImageNames = @[@"tabbar_0_select", @"tabbar_1_select", @"tabbar_2_select",@"tabbar_3_select"];
    NSArray *normalImageNames = @[@"tabbar_0_default", @"tabbar_1_default", @"tabbar_2_default",@"tabbar_3_default"];
    NSArray *tabbarTitles = @[@"体重预测",@"备装建议",@"黄疸识别",@"我的"];

    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull item, NSUInteger idx, BOOL * _Nonnull stop) {
        item.image = [[UIImage imageNamed:normalImageNames[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = [[UIImage imageNamed:selectImageNames[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.title = tabbarTitles[idx];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:DEFAULTREDCOLOR} forState:UIControlStateSelected];
    }];

    //更改tabbar的文字、颜色

    CGSize size = CGSizeMake(self.tabBar.bounds.size.width/self.tabBar.items.count*0.6, self.tabBar.bounds.size.height*0.95);
    UIImage * bgImage = [self drawTabBarItemBgImageWithSize:size];
    self.tabBar.selectionIndicatorImage = [UIImage createRoundedRectImage:bgImage size:bgImage.size radius:6];
   
    //默认进入显示首页
}

-(UIImage *)drawTabBarItemBgImageWithSize:(CGSize)size{
    UIGraphicsBeginImageContext(size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(ctx, 255.0f, 255.0f, 255.0f, 1.0);
    CGContextFillRect(ctx, CGRectMake(0, 0, size.width, size.height));
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
    
}


#pragma mark-------判断启动页面加载图片内容
-(void)addGuidanceView{
    guidView = [JDDGuidanceView shareGuidanceView];
    [self.view addSubview:guidView];
    [self.view bringSubviewToFront:guidView];
}



@end
